package net.akkz.action.feature;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.akkz.beanFactory.BeanFactory;
import net.akkz.model.Student;
import net.akkz.server.FultureServer;

@WebServlet(name="FultureFind", urlPatterns="/student/fultureFind.do")
public class FultureFind extends HttpServlet
{
	private FultureServer fultureServer;
	
	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response)  throws IOException,ServletException
	{
		int start = Integer.parseInt(request.getParameter("start"));
		int end = Integer.parseInt(request.getParameter("end"));
		
		String kind = request.getParameter("kind");
		
		if(kind.equals("time"))
			request.setAttribute("fultures", fultureServer.findFulture(start, end));
		else
			request.setAttribute("fultures", fultureServer.findFultureOrderByJoined(start, end));
		
		request.getRequestDispatcher("/jsp/fultures.jsp").forward(request, response);
	}
	
	@Override
	public void init()
	{
		BeanFactory  bf = (BeanFactory) this.getServletContext().getAttribute("beanFactory");
		
		fultureServer = bf.getBean("fultureServer");
	}

}
